﻿using System;
using NJabber.Stream.Elements;

namespace NJabber.Client.StanzaFactories
{
    public class PresenceStanzaFactory : StanzaFactory<PresenceMessageParameters>, IPresenceStanzaFactory
    {
        public Stanza CreateAvailabilityMessage(bool isAvailable, AvailabilityStatus status, string statusDescription)
        {
            if (isAvailable) return CreatePresenceStanza(string.Empty, status, statusDescription);
            return CreatePresenceStanza(PresenceStanzaType.Unavailable, status, statusDescription);
        }

        private Stanza CreatePresenceStanza(string type, AvailabilityStatus status, string statusDescription)
        {
            PresenceStanza stanza = CreateStanza<PresenceStanza>();
            stanza.Type = type;
            stanza.Availability = GetStringForAvailabilityStatus(status);
            stanza.StatusText = statusDescription;
            return stanza;
        }

        private string GetStringForAvailabilityStatus(AvailabilityStatus status)
        {
            return ConvertHelper.AvailabilityStatusToString(status);
        }

        public Stanza CreatePresenceMessage(PresenceMessageParameters parameters)
        {
            throw new System.NotImplementedException();
        }
    }
}
